package com.chap18;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

/**
 * <p>
 * <code>LockEscalationDemo</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-05-17 16:29
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
@Slf4j
public class LockEscalationDemo13 {
    public static void main(String[] args) throws InterruptedException {

        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (obj) {
                log.debug(Thread.currentThread().getName() + "获取锁执行。。。\n" + ClassLayout.parseInstance(obj).toPrintable());//10 重量级锁
            }
            log.debug(Thread.currentThread().getName() + "释放锁。。。\n" + ClassLayout.parseInstance(obj).toPrintable());//10 重量级锁


        }, "thread1");
        t1.start();

        Thread t2 = new Thread(() -> {
            synchronized (obj) {
                log.debug(Thread.currentThread().getName() + "获取锁执行。。。\n" + ClassLayout.parseInstance(obj).toPrintable());//10 重量级锁
            }
            log.debug(Thread.currentThread().getName() + "释放锁。。。\n" + ClassLayout.parseInstance(obj).toPrintable());//10 重量级锁


        }, "thread2");
        t2.start();

        Thread.sleep(5000);
        log.debug(Thread.currentThread().getName()+"释放锁。。。\n"+ClassLayout.parseInstance(obj).toPrintable());//001 无锁
     }
}
